<?php
namespace app\admin\model\system;
use think\Model;
class Menu extends Model
{
    protected $table="cp_auth_menu";

    /**
     * @Notes:获取分页菜单
     * @User: chenping
     * @email: 375129701@qq.com
     * @param int $page
     * @param int $limit
     * @return $this[]|\think\Paginator
     */
    public function getPageMenu($page=1,$limit=20)
    {
        return $this->paginate($limit);
    }


    /**
     * @Notes: 全部菜单列表
     * @User: chenping
     * @email: 375129701@qq.com
     * @return array
     */
    public function getMenu()
    {
        return $this->where("status", 1)
            ->field("id,url_link as href,name,title as text,icon ,is_view as hasView,parent_id,status,is_view")
            ->select()
            ->toArray();
    }

    /**
     * @Notes: 根据id 获取菜单数据
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $id
     * @return array
     */
    public function findMenu($id)
    {
        return $this->where("status", 1)
            ->field("id,url_link as href,name,title as text,icon ,is_view as hasView,parent_id,status,is_view")
            ->find($id);
    }


    /**
     * @Notes:添加菜单
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $data
     * @return static
     */
    public function addMenu($data)
    {
        return $this->create($data);
    }

    /**
     * @Notes:删除菜单
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $where
     * @return bool
     */
    public function delMenu($where)
    {
        return $this->where($where)->delete();
    }

    /**
     * @Notes:修改菜单
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $data
     * @param array $where
     * @return static
     */
    public function saveMenu($data,$where=[])
    {
        return $this->where($where)
            ->update($data);
    }
}